import i18n from 'i18next'
import { useTranslation } from 'react-i18next';

export type PrimitiveType = string | number | boolean | null | undefined | Date;

export function useIntl() {
    const { t, i18n, ready } = useTranslation();
    function formatMessage(options: {
        id: string;
        module?: string;
    }, values?: Record<string, PrimitiveType>) {
        const { id, module } = options
        return t(`${module ? module + '.' : ''}${id}`, values)
    }
    return { t, i18n, ready, formatMessage }
}

export function getLocale() {
    return i18n.language
}

export function setLocale(lng: string) {
    return i18n.changeLanguage(lng)
}